package com.vueperson.vueperson.t1.CreationalPattern.PrototypePattern.PrototypeManager;


import java.util.Hashtable;

public class PrototypeManager {



    private Hashtable prototypeTable=new Hashtable();   //使用Hashtable存储原型对象
    public PrototypeManager(){
        prototypeTable.put("A",new ConcretePrototypeA());
        prototypeTable.put("B",new ConcretePrototypeB());

    }

    //静态内部类
    private static class HolderClass{
        private final static PrototypeManager instance=new PrototypeManager();
    }

    public static PrototypeManager getInstance(){
        return PrototypeManager.HolderClass.instance;

    }

    public void add(String key, Prototype prototype){
        prototypeTable.put(key,prototype);

    }

    public  Prototype get(String key){
        Prototype clone=null;
        clone= ((Prototype) prototypeTable.get(key)).clone();
        return clone;
    }


}
